package org.edu.dao.impl;

import java.util.List;

import javax.faces.model.SelectItem;

import org.edu.dao.TeacherLessonDao;
import org.edu.model.TeacherLesson;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TeacherLessonDaoImpl implements TeacherLessonDao {

	@Autowired
	private SessionFactory sessionFactory;
	public TeacherLessonDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void save(TeacherLesson teacherLesson) throws Exception {
		sessionFactory.getCurrentSession().save(teacherLesson);
	}

	@Override
	public void update(TeacherLesson teacherLesson) throws Exception {
		sessionFactory.getCurrentSession().update(teacherLesson);
	}

	@Override
	public void remove(TeacherLesson teacherLesson) throws Exception {
		sessionFactory.getCurrentSession().delete(teacherLesson);
	}

	@Override
	public List<TeacherLesson> teacherLessons() {
		return sessionFactory.getCurrentSession().createQuery("from TeacherLesson").list();
	}

	@Override
	public TeacherLesson findById(Long teacher_lesson_id) throws Exception {
		return (TeacherLesson) sessionFactory.getCurrentSession().load(TeacherLesson.class, teacher_lesson_id);
	}

	@Override
	public List<SelectItem> selectItems() {
		return sessionFactory.getCurrentSession().createQuery("from TeacherLesson").list();
	}

}
